package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @projectName: heima-leadnews
 * @package: com.heima.wemedia.controller.v1
 * @className: NewsController
 * @author: 躺着认真玩
 * @description: 文章内容模块
 * @date: 2025/5/19 7:58
 * @version: 1.0
 */
@RestController
@RequestMapping("/api/v1/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * @param dto
     * 文章内容分页查询
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult list(@RequestBody WmNewsPageReqDto dto){
        return newsService.findAll(dto);
    }

    /**
     * @param wmNewsDto
     * 保存|修改-草稿|非草稿
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        newsService.submit(wmNewsDto);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 文章上架或者下架
     *
     * @return {@link ResponseResult }
     */
    @PostMapping("/down_or_up")
    public ResponseResult upOrDown(@RequestBody WmNewsDto wmNewsDto){
        newsService.upOrDown(wmNewsDto);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
